//
// Created by YueChuan on 2023/3/26.
//

#include "mutex.h"

namespace yuechuan {
    Semaphore::Semaphore(uint32_t count) {
        if (sem_init(&m_semaphore, 0, count)) {
            throw std::logic_error("sem_inti error");
        }
    }

    Semaphore::~Semaphore() {
        sem_destroy(&m_semaphore);
    }

    void Semaphore::wait() {

        if (sem_wait(&m_semaphore)) {
            throw std::logic_error("sem_wait error");
        }

    }

    void Semaphore::notify() {
        if (sem_post(&m_semaphore)) {
            throw std::logic_error("sem_post error");
        }
    }
}// namespace yuechuan

